package com.aij.starter.service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.springframework.beans.factory.annotation.Autowired;

import com.aij.starter.config.AijProperties;

/**
 * AIJ服务类
 * @author aij
 */
public class AijService {
	
    @Autowired
    private AijProperties properties;

    public AijProperties getAijProperties() {
        return properties;
    }

    public void setAijProperties(AijProperties properties) {
        this.properties = properties;
    }
    
    @PostConstruct
    public void init() {
    	initLlm();
    }
    
    public void initLlm() {
    	if (!properties.isLlmEnable()) return;
    	LlmService.Instance(properties.getLlmModel(), properties.getLlmType());
    	if (LlmService.instance == null) return;
    	LlmService.instance.Initialize();
    }
    
    public void runLlm(String word, LlmService.LLMCallback callback) {
    	if (word == null || LlmService.instance == null) return;
    	LlmService.instance.Run(word, callback);
    }
    
    @PreDestroy
    public void destroy() {
    	if (LlmService.instance != null) {
        	LlmService.instance.Destroy();
    	}
    }
}
